package com.vivi.feverdiagnose;

import com.vivi.feverdiagnose.utils.ConnectionDetector;
import com.vivi.feverdiagnose.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Window;
import android.view.WindowManager;

public class Splash extends Activity {

	protected int _splashTime = 1800;
	private Thread splashTread;
	
    ConnectionDetector cd;
    Boolean isInternetPresent = false;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        
    	requestWindowFeature(Window.FEATURE_NO_TITLE);

		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		final Splash S = this;
		cd = new ConnectionDetector(getApplicationContext());

		// thread for displaying the SplashScreen
		splashTread = new Thread() {
			@Override
			public void run() {
				try {
					synchronized (this) {
						wait(_splashTime);
					}

				} catch (InterruptedException e) {
				} finally {
					finish();
					isInternetPresent = cd.isConnectingToInternet();
					if (isInternetPresent) {
						Intent i = new Intent();
						i.setClass(S, MainLoadData.class);
						i.putExtra("url", "");
						startActivity(i);
					}else{
						Intent i = new Intent();
						i.setClass(S, MainMenu.class);
						i.putExtra("url", "");
						startActivity(i);
					}					
				}
			}
		};
		splashTread.start();
    }   
}
